<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../assets/axios/axios.js"></script>
    <script>
        // 双参数方法
        // axios.get(url[, config])
        // axios.delete(url[, config])
        // axios.head(url[, config])
        // axios.options(url[, config])

        // 参数url：定义请求地址
        // 参数config：定义axios的基础配置,参数等效于 axios(options) 的options
        

        axios.get("http://127.0.0.1:3000/api/list")
            .then(function( response ){
                console.log( response )
            })

        axios.get("http://127.0.0.1:3000/api/query",{
            params:{
                username:"tom",
                age:23
            }
        })
        .then(function( response ){
            console.log( response )
        })


        // 三参数方法
        //      方法( arg1,[ arg2, [arg3] ] ) => arg2 和 arg3 为可选参数；arg3的传递依存于arg2
        // axios.post(url[, data[, config]])
        // axios.put(url[, data[, config]])
        // axios.patch(url[, data[, config]])

        // 参数data：请求报文体参数,取值等效于 axios(options) options参数中的 data 属性

        axios.post("http://127.0.0.1:3000/api/params")
            .then(function( response ){
                console.log( response )
            })

        axios.post(
            "http://127.0.0.1:3000/api/params",
            {
                name:"tom",
                age:23
            }
        )
        .then(function( response ){
            console.log( response )
        })

        axios.post(
            "http://127.0.0.1:3000/api/params",
            {
                name:"tom",
                age:23
            },
            {
                // 在config中通过配置data定义的请求体参数不被读取
                data:{
                    sex:"男",
                    age:33
                },
                headers:{
                    test:"user set headers"
                }
            }
        )
        .then(function( response ){
            console.log( response )
        })

        axios.post("http://127.0.0.1:3000/api/params",null,{
            headers:{
                test:"user set headers"
            }
        })
        .then(function( response ){
            console.log( response )
        })
    </script>
</head>
<body>
    
</body>
</html>